package com.briup;

import java.util.concurrent.TimeUnit;

/**
 * 什么是线程
 *
 * @auther thb
 * @date 2021/9/3
 */
public class T1_WhatIsThread {

    public static void main(String[] args) {
        //new Thread1().run();   // 调用run方法
        new Thread1().start(); // 开启线程

        for (int i = 0; i < 5; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "：" + i);
        }

    }

}

class Thread1 extends Thread {

    @Override
    public void run() {
        Thread.currentThread().setName("createThread");
        for (int i = 0; i < 5; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "：" + i);
        }
    }
}

